package com.xunyin.modules.index.rest;

import com.xunyin.annotation.AnonymousAccess;
import com.xunyin.modules.index.service.IndexService;
import com.xunyin.modules.order.param.ExpressParam;
import com.xunyin.modules.shareorder.service.TShareOrderService;
import com.xunyin.modules.shareorder.service.dto.ShareOrderCountDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author xunyinyunshang  <3594419785@qq.com>
 * @date 2022-11-15
 */
@AllArgsConstructor
// @RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "共享空间：后台首页统计分析等")
@RestController
@RequestMapping("api")
@Slf4j
public class IndexController {

    private final IndexService indexService;

    private final TShareOrderService tShareOrderService;

    /**
     * 首页订单/用户等统计
     *
     * @return OrderTimeDataDto
     */
    @GetMapping(value = "/data/count")
    @AnonymousAccess
    public ResponseEntity getCount(HttpServletRequest request, @RequestParam("storeId") Integer storeId) {

        return new ResponseEntity<>(indexService.getIndexDataStat(storeId), HttpStatus.OK);
    }

    /**
     * @Valid 根据包间分类统计订单占比
     */
    @GetMapping("/yxStoreOrder/orderCount")
    @ApiOperation(value = "根据包间分类统计订单占比", notes = "根据包间分类统计订单占比", response = ExpressParam.class)
    public ResponseEntity orderCount(HttpServletRequest request, @RequestParam("storeId") Integer storeId) {
        ShareOrderCountDto orderCountDto = tShareOrderService.getOrderCount(storeId);
        return new ResponseEntity<>(orderCountDto, HttpStatus.OK);
    }

    /**
     * 返回本月订单金额与数量chart
     *
     * @return map
     */
    @GetMapping(value = "/data/chart")
    @AnonymousAccess
    public ResponseEntity getChart(HttpServletRequest request, @RequestParam("storeId") Integer storeId) {
        return new ResponseEntity<>(tShareOrderService.chartCount(storeId), HttpStatus.OK);
    }
}
